<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>My Project: drogon::WebSocketClient类 参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">My Project
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacedrogon.html">drogon</a></li><li class="navelem"><a class="el" href="classdrogon_1_1WebSocketClient.html">WebSocketClient</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public 成员函数</a> &#124;
<a href="#pub-static-methods">静态 Public 成员函数</a> &#124;
<a href="classdrogon_1_1WebSocketClient-members.html">所有成员列表</a>  </div>
  <div class="headertitle"><div class="title">drogon::WebSocketClient类 参考<span class="mlabels"><span class="mlabel">abstract</span></span></div></div>
</div><!--header-->
<div class="contents">

<p>WebSocket client abstract class  
 <a href="classdrogon_1_1WebSocketClient.html#details">更多...</a></p>

<p><code>#include &lt;<a class="el" href="WebSocketClient_8h_source.html">WebSocketClient.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public 成员函数</h2></td></tr>
<tr class="memitem:a565eefde4f502bb10cc321d009bfed70" id="r_a565eefde4f502bb10cc321d009bfed70"><td class="memItemLeft" align="right" valign="top">virtual <a class="el" href="namespacedrogon.html#a963450dc03553ccb1c4bbc8479404eb9">WebSocketConnectionPtr</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a565eefde4f502bb10cc321d009bfed70">getConnection</a> ()=0</td></tr>
<tr class="memdesc:a565eefde4f502bb10cc321d009bfed70"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the WebSocket connection that is typically used to send messages.  <br /></td></tr>
<tr class="separator:a565eefde4f502bb10cc321d009bfed70"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a69b64de687b402c2be336d0ec9c2baea" id="r_a69b64de687b402c2be336d0ec9c2baea"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a69b64de687b402c2be336d0ec9c2baea">setMessageHandler</a> (const std::function&lt; void(std::string &amp;&amp;message, const <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> &amp;, const <a class="el" href="namespacedrogon.html#a60c960a4500d47d200b72356dfcd06e8">WebSocketMessageType</a> &amp;)&gt; &amp;callback)=0</td></tr>
<tr class="memdesc:a69b64de687b402c2be336d0ec9c2baea"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set messages handler. When a message is received from the server, the callback is called.  <br /></td></tr>
<tr class="separator:a69b64de687b402c2be336d0ec9c2baea"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9964be7a12553377c6fc2d9e514d7b3b" id="r_a9964be7a12553377c6fc2d9e514d7b3b"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a9964be7a12553377c6fc2d9e514d7b3b">setConnectionClosedHandler</a> (const std::function&lt; void(const <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> &amp;)&gt; &amp;callback)=0</td></tr>
<tr class="memdesc:a9964be7a12553377c6fc2d9e514d7b3b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the connection closing handler. When the websocket connection is closed, the callback is called  <br /></td></tr>
<tr class="separator:a9964be7a12553377c6fc2d9e514d7b3b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aad0a944fd92463ef578c0990f3bce4a5" id="r_aad0a944fd92463ef578c0990f3bce4a5"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#aad0a944fd92463ef578c0990f3bce4a5">connectToServer</a> (const <a class="el" href="namespacedrogon.html#a5200699555f98a809538342baa167aad">HttpRequestPtr</a> &amp;request, const <a class="el" href="namespacedrogon.html#a888b4af6a797800c9eda52b877925108">WebSocketRequestCallback</a> &amp;callback)=0</td></tr>
<tr class="memdesc:aad0a944fd92463ef578c0990f3bce4a5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Connect to the server.  <br /></td></tr>
<tr class="separator:aad0a944fd92463ef578c0990f3bce4a5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af383e9333bd8f3611b671eaff48cd503" id="r_af383e9333bd8f3611b671eaff48cd503"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#af383e9333bd8f3611b671eaff48cd503">setCertPath</a> (const std::string &amp;cert, const std::string &amp;key)=0</td></tr>
<tr class="memdesc:af383e9333bd8f3611b671eaff48cd503"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the client certificate used by the HTTP connection  <br /></td></tr>
<tr class="separator:af383e9333bd8f3611b671eaff48cd503"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7bc93157c9ba2bf699f37f71b44d1805" id="r_a7bc93157c9ba2bf699f37f71b44d1805"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a7bc93157c9ba2bf699f37f71b44d1805">addSSLConfigs</a> (const std::vector&lt; std::pair&lt; std::string, std::string &gt; &gt; &amp;sslConfCmds)=0</td></tr>
<tr class="memdesc:a7bc93157c9ba2bf699f37f71b44d1805"><td class="mdescLeft">&#160;</td><td class="mdescRight">Supplies command style options for <code>SSL_CONF_cmd</code>  <br /></td></tr>
<tr class="separator:a7bc93157c9ba2bf699f37f71b44d1805"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7f38b65903f3001a4baa4cdf486e41cc" id="r_a7f38b65903f3001a4baa4cdf486e41cc"><td class="memItemLeft" align="right" valign="top">virtual trantor::EventLoop *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a7f38b65903f3001a4baa4cdf486e41cc">getLoop</a> ()=0</td></tr>
<tr class="memdesc:a7f38b65903f3001a4baa4cdf486e41cc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the event loop of the client;  <br /></td></tr>
<tr class="separator:a7f38b65903f3001a4baa4cdf486e41cc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a70db4772f4e8fb5d888eaa3b806cae47" id="r_a70db4772f4e8fb5d888eaa3b806cae47"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a70db4772f4e8fb5d888eaa3b806cae47">stop</a> ()=0</td></tr>
<tr class="memdesc:a70db4772f4e8fb5d888eaa3b806cae47"><td class="mdescLeft">&#160;</td><td class="mdescRight">Stop trying to connect to the server or close the connection.  <br /></td></tr>
<tr class="separator:a70db4772f4e8fb5d888eaa3b806cae47"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a23207481037a6952912466c8062d5469" id="r_a23207481037a6952912466c8062d5469"><td class="memItemLeft" align="right" valign="top">virtual&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a23207481037a6952912466c8062d5469">~WebSocketClient</a> ()=default</td></tr>
<tr class="separator:a23207481037a6952912466c8062d5469"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-static-methods" name="pub-static-methods"></a>
静态 Public 成员函数</h2></td></tr>
<tr class="memitem:a27786bef2a65c9f4fd3dc7692fde8b1b" id="r_a27786bef2a65c9f4fd3dc7692fde8b1b"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a27786bef2a65c9f4fd3dc7692fde8b1b">newWebSocketClient</a> (const std::string &amp;ip, uint16_t port, bool useSSL=false, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)</td></tr>
<tr class="memdesc:a27786bef2a65c9f4fd3dc7692fde8b1b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a websocket client using the given ip and port to connect to server.  <br /></td></tr>
<tr class="separator:a27786bef2a65c9f4fd3dc7692fde8b1b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a019d63ecbee5c1022ddf50c445b5cc82" id="r_a019d63ecbee5c1022ddf50c445b5cc82"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classdrogon_1_1WebSocketClient.html#a019d63ecbee5c1022ddf50c445b5cc82">newWebSocketClient</a> (const std::string &amp;hostString, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)</td></tr>
<tr class="separator:a019d63ecbee5c1022ddf50c445b5cc82"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<div class="textblock"><p>WebSocket client abstract class </p>
</div><h2 class="groupheader">构造及析构函数说明</h2>
<a id="a23207481037a6952912466c8062d5469" name="a23207481037a6952912466c8062d5469"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a23207481037a6952912466c8062d5469">&#9670;&#160;</a></span>~WebSocketClient()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual drogon::WebSocketClient::~WebSocketClient </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span><span class="mlabel">default</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<h2 class="groupheader">成员函数说明</h2>
<a id="a7bc93157c9ba2bf699f37f71b44d1805" name="a7bc93157c9ba2bf699f37f71b44d1805"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7bc93157c9ba2bf699f37f71b44d1805">&#9670;&#160;</a></span>addSSLConfigs()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::addSSLConfigs </td>
          <td>(</td>
          <td class="paramtype">const std::vector&lt; std::pair&lt; std::string, std::string &gt; &gt; &amp;&#160;</td>
          <td class="paramname"><em>sslConfCmds</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Supplies command style options for <code>SSL_CONF_cmd</code> </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">sslConfCmds</td><td>options for SSL_CONF_cmd </td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>注解</dt><dd>this method has no effect if the HTTP client is communicating via unencrypted HTTP <div class="fragment"><div class="line"><a class="code hl_function" href="classdrogon_1_1WebSocketClient.html#a7bc93157c9ba2bf699f37f71b44d1805">addSSLConfigs</a>({{<span class="stringliteral">&quot;-dhparam&quot;</span>, <span class="stringliteral">&quot;/path/to/dhparam&quot;</span>}, {<span class="stringliteral">&quot;-strict&quot;</span>, <span class="stringliteral">&quot;&quot;</span>}});</div>
<div class="ttc" id="aclassdrogon_1_1WebSocketClient_html_a7bc93157c9ba2bf699f37f71b44d1805"><div class="ttname"><a href="classdrogon_1_1WebSocketClient.html#a7bc93157c9ba2bf699f37f71b44d1805">drogon::WebSocketClient::addSSLConfigs</a></div><div class="ttdeci">virtual void addSSLConfigs(const std::vector&lt; std::pair&lt; std::string, std::string &gt; &gt; &amp;sslConfCmds)=0</div><div class="ttdoc">Supplies command style options for SSL_CONF_cmd</div></div>
</div><!-- fragment --> </dd></dl>

</div>
</div>
<a id="aad0a944fd92463ef578c0990f3bce4a5" name="aad0a944fd92463ef578c0990f3bce4a5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aad0a944fd92463ef578c0990f3bce4a5">&#9670;&#160;</a></span>connectToServer()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::connectToServer </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="namespacedrogon.html#a5200699555f98a809538342baa167aad">HttpRequestPtr</a> &amp;&#160;</td>
          <td class="paramname"><em>request</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="namespacedrogon.html#a888b4af6a797800c9eda52b877925108">WebSocketRequestCallback</a> &amp;&#160;</td>
          <td class="paramname"><em>callback</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Connect to the server. </p>

</div>
</div>
<a id="a565eefde4f502bb10cc321d009bfed70" name="a565eefde4f502bb10cc321d009bfed70"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a565eefde4f502bb10cc321d009bfed70">&#9670;&#160;</a></span>getConnection()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual <a class="el" href="namespacedrogon.html#a963450dc03553ccb1c4bbc8479404eb9">WebSocketConnectionPtr</a> drogon::WebSocketClient::getConnection </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Get the WebSocket connection that is typically used to send messages. </p>

</div>
</div>
<a id="a7f38b65903f3001a4baa4cdf486e41cc" name="a7f38b65903f3001a4baa4cdf486e41cc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7f38b65903f3001a4baa4cdf486e41cc">&#9670;&#160;</a></span>getLoop()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual trantor::EventLoop * drogon::WebSocketClient::getLoop </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Get the event loop of the client; </p>

</div>
</div>
<a id="a019d63ecbee5c1022ddf50c445b5cc82" name="a019d63ecbee5c1022ddf50c445b5cc82"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a019d63ecbee5c1022ddf50c445b5cc82">&#9670;&#160;</a></span>newWebSocketClient() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> drogon::WebSocketClient::newWebSocketClient </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>hostString</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">trantor::EventLoop *&#160;</td>
          <td class="paramname"><em>loop</em> = <code>nullptr</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>useOldTLS</em> = <code>false</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>validateCert</em> = <code>true</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Create a websocket client using the given hostString to connect to server </p><dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">hostString</td><td>must be prefixed by 'ws://' or 'wss://' Examples for hostString: <div class="fragment"><div class="line">wss:<span class="comment">//www.google.com</span></div>
<div class="line">ws:<span class="comment">//www.google.com</span></div>
<div class="line">wss:<span class="comment">//127.0.0.1:8080/</span></div>
<div class="line">ws:<span class="comment">//127.0.0.1</span></div>
</div><!-- fragment --> </td></tr>
    <tr><td class="paramname">loop</td><td>if the parameter is set to nullptr, the client uses the <a class="el" href="classdrogon_1_1HttpAppFramework.html">HttpAppFramework</a>'s main event loop, otherwise it runs in the loop identified by the parameter. </td></tr>
    <tr><td class="paramname">useOldTLS</td><td>If the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS. </td></tr>
    <tr><td class="paramname">validateCert</td><td>If the parameter is set to true, the client validates the server certificate when SSL handshaking. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>注解</dt><dd>Don't add path and parameters in hostString, the request path and parameters should be set in HttpRequestPtr when calling the <a class="el" href="classdrogon_1_1WebSocketClient.html#aad0a944fd92463ef578c0990f3bce4a5" title="Connect to the server.">connectToServer()</a> method. </dd></dl>

</div>
</div>
<a id="a27786bef2a65c9f4fd3dc7692fde8b1b" name="a27786bef2a65c9f4fd3dc7692fde8b1b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a27786bef2a65c9f4fd3dc7692fde8b1b">&#9670;&#160;</a></span>newWebSocketClient() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> drogon::WebSocketClient::newWebSocketClient </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>ip</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint16_t&#160;</td>
          <td class="paramname"><em>port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>useSSL</em> = <code>false</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">trantor::EventLoop *&#160;</td>
          <td class="paramname"><em>loop</em> = <code>nullptr</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>useOldTLS</em> = <code>false</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>validateCert</em> = <code>true</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Create a websocket client using the given ip and port to connect to server. </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">ip</td><td>The ip address of the server. </td></tr>
    <tr><td class="paramname">port</td><td>The port of the server. </td></tr>
    <tr><td class="paramname">useSSL</td><td>If useSSL is set to true, the client connects to the server using SSL. </td></tr>
    <tr><td class="paramname">loop</td><td>If the loop parameter is set to nullptr, the client uses the <a class="el" href="classdrogon_1_1HttpAppFramework.html">HttpAppFramework</a>'s event loop, otherwise it runs in the loop identified by the parameter. </td></tr>
    <tr><td class="paramname">useOldTLS</td><td>If the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS. </td></tr>
    <tr><td class="paramname">validateCert</td><td>If the parameter is set to true, the client validates the server certificate when SSL handshaking. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>HttpClientPtr The smart pointer to the new client object. </dd>
<dd>
WebSocketClientPtr The smart pointer to the WebSocket client. </dd></dl>
<dl class="section note"><dt>注解</dt><dd>The ip parameter support for both ipv4 and ipv6 address </dd></dl>

</div>
</div>
<a id="af383e9333bd8f3611b671eaff48cd503" name="af383e9333bd8f3611b671eaff48cd503"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af383e9333bd8f3611b671eaff48cd503">&#9670;&#160;</a></span>setCertPath()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::setCertPath </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>cert</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>key</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set the client certificate used by the HTTP connection </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">cert</td><td>Path to the certificate </td></tr>
    <tr><td class="paramname">key</td><td>Path to the certificate's private key </td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>注解</dt><dd>this method has no effect if the HTTP client is communicating via unencrypted HTTP </dd></dl>

</div>
</div>
<a id="a9964be7a12553377c6fc2d9e514d7b3b" name="a9964be7a12553377c6fc2d9e514d7b3b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9964be7a12553377c6fc2d9e514d7b3b">&#9670;&#160;</a></span>setConnectionClosedHandler()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::setConnectionClosedHandler </td>
          <td>(</td>
          <td class="paramtype">const std::function&lt; void(const <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> &amp;)&gt; &amp;&#160;</td>
          <td class="paramname"><em>callback</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set the connection closing handler. When the websocket connection is closed, the callback is called </p>
<p>Set the connection closing handler. When the connection is established or closed, the <code>callback</code> is called with a bool parameter. </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">callback</td><td>The function to call when the connection is closed. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a69b64de687b402c2be336d0ec9c2baea" name="a69b64de687b402c2be336d0ec9c2baea"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a69b64de687b402c2be336d0ec9c2baea">&#9670;&#160;</a></span>setMessageHandler()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::setMessageHandler </td>
          <td>(</td>
          <td class="paramtype">const std::function&lt; void(std::string &amp;&amp;message, const <a class="el" href="namespacedrogon.html#ad0c26abc9bbfb0532bc364bfeecb9b74">WebSocketClientPtr</a> &amp;, const <a class="el" href="namespacedrogon.html#a60c960a4500d47d200b72356dfcd06e8">WebSocketMessageType</a> &amp;)&gt; &amp;&#160;</td>
          <td class="paramname"><em>callback</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set messages handler. When a message is received from the server, the callback is called. </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">callback</td><td>The function to call when a message is received. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a70db4772f4e8fb5d888eaa3b806cae47" name="a70db4772f4e8fb5d888eaa3b806cae47"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a70db4772f4e8fb5d888eaa3b806cae47">&#9670;&#160;</a></span>stop()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void drogon::WebSocketClient::stop </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Stop trying to connect to the server or close the connection. </p>

</div>
</div>
<hr/>该类的文档由以下文件生成:<ul>
<li><a class="el" href="WebSocketClient_8h_source.html">WebSocketClient.h</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>
